package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.Bean.Comment;
import com.yc.yyds.Bean.Result;
import com.yc.yyds.biz.BizException;
import com.yc.yyds.biz.CommentBiz;
import com.yc.yyds.dao.CommentsDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryOneCommentServlet", value = "/QueryOneCommentServlet.s")
public class QueryOneCommentServlet extends HttpServlet {
    CommentBiz biz = new CommentBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String movieid = request.getParameter("movieid");
        Result result;
        try {
            List<Comment> data = biz.queryOneComment(movieid);
            result = new Result(1,"查询成功",data);
            System.out.println("查出的数据:"+data.size());
            String json = new Gson().toJson(result);
            response.getWriter().append(json);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);
            String json = new Gson().toJson(result);
            response.getWriter().append(json);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
